#include <buola/mat.h>
#include <buola/mat/prettyprint.h>
#include <buola/mat/svd.h>
#include <buola/mat/traits_typename.h>

using namespace buola;

int main(int /*argc*/,char** argv)
{
    mat::CMat_d a=mat::random(2000,2000,std::normal_distribution<double>());
    mat::CMat_d a2=mat::random(2000,2000,std::normal_distribution<double>());
    mat::CVec_d b(2000);

    start_timer();
    for(int r=0;r<a.Rows();r++)
    {
        b(r)=1;
        for(int c=0;c<a.Cols();c++)
        {
            b(r)*=-a(r,c)+a2(r,c);
        }
    }
    end_timer();
    msg_info() << sum(b) << "," << var(b) << "\n";
    
    start_timer();
    b=prod(rows(-a+a2));
    end_timer();
    msg_info() << sum(b) << "," << var(b) << "\n";
    
    start_timer();
    b=sum(rows(-a+a2));
    end_timer();
    msg_info() << sum(b) << "," << var(b) << "\n";
    
    double lSum=0.0;
    start_timer();
    for(int r=0;r<a.Rows();r++)
    {
        for(int c=0;c<a.Cols();c++)
        {
            lSum+=-a(r,c)+a2(r,c);
        }
    }
    end_timer();
    msg_info() << lSum << "\n";

    start_timer();
    lSum=prod(-a+a2);
    end_timer();
    msg_info() << lSum << "\n";

    start_timer();
    lSum=sum(-a+a2);
    end_timer();
    msg_info() << lSum << "\n";

    start_timer();
    lSum=sum(a);
    end_timer();
    msg_info() << lSum << "\n";

    start_timer();
    b=sum(rows(a));
    end_timer();
    msg_info() << sum(b) << "\n";

    start_timer();
    lSum=mean(a);
    end_timer();
    msg_info() << lSum << "\n";

    start_timer();
    lSum=prod(a);
    end_timer();
    msg_info() << lSum << "\n";

    msg_info() << "maximum\n";
    start_timer();
    for(int r=0;r<a.Rows();r++)
    {
        b(r)=1;
        for(int c=0;c<a.Cols();c++)
        {
            b(r)*=-a(r,c)+a2(r,c);
        }
    }
    end_timer();
    msg_info() << sum(b) << "," << var(b) << "\n";
    
    start_timer();
    b=prod(rows(-a+a2));
    end_timer();
    msg_info() << sum(b) << "," << var(b) << "\n";
}